home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / MSDBDynaField.inc < prev    next >
Encoding:
Text File  |  1998-11-20  |  12.2 KB  |  320 lines

  1. <!--#INCLUDE FILE="MSGlobal.inc"-->
  2. <SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
  3. ////////////////////////////////////////////////////////////////////
  4. //                                                                //
  5. //   Fusion ASP Components                                        //
  6. //   Custom JScript Object: MSDBDynaField                            // 
  7. //                                                                //
  8. ////////////////////////////////////////////////////////////////////
  9. /*
  10. Object:       MSDBDynaField  
  11.  
  12. Version:      1.0  9/04/97
  13.  
  14. Written By:   Application Methods, Inc.
  15.               6300 Southcenter Blvd.
  16.               Seattle, WA 98188
  17.               (206) 244-2400
  18.               http://www.appmethods.com
  19.  
  20.  
  21. Description:   This object definition describes properties and methods for a 
  22.    dynamically constructed edit box or label.  From this object definition, a
  23.    valid HTML edit box or label may be constructed from a LiveWire database cursor object.  
  24.    One column from the cursor is selected to be the value and for the edit box or label, and the option
  25.    isEditable is used to determine which will be created by the .java file.
  26.  
  27. Note:   Generation of a number of hidden fields is necessary to pass information
  28.    on to other components.  All hidden fields created by this object are prefixed
  29.    with 'amaspHidden_' or 'amlivewireComponent_'.  Devlopers should never create
  30.    any form element with these prefixes or unexpected results will occur.
  31.  
  32. Properties:
  33.    name - Name of Dynafield
  34.    useQuery - Whether to use value from query (otherwise uses default)
  35.    queryComponentName - Name of query component to be used
  36.    defaultValue - default value used if useQuery is false
  37.    dataField - field name
  38.    dataType - type of field
  39.    isEditable - Whether the field should be editable or rather whether the field 
  40.         is displayed as text or an input box
  41.    visibleLength - Length of input box, in characters
  42.    maxLength - Maximum accepted input length, in characters
  43.    visibleHeight - Height of input box, in approximated lines
  44.    font - Font face for text
  45.    fontSize - Font size for text
  46.    fontColor - Font color for text
  47.    bold - Whether text is bold
  48.    italic - Whether text is italicized
  49.    underline - Whether text is underlined
  50.  
  51. Methods:
  52.    getColumnValue  - Gets values for dataField
  53.    render - renders visual elements of Dynafield
  54.    emitProperties - displays all the properties for the Dynafield
  55.  
  56.  
  57. Usage:   The following example shows a value being displayed to create a edit box
  58.    containing a value from the table "lookup."  The column named "ShipCity" will be
  59.    used to get a value.  
  60.  
  61. <HTML>
  62. <HEAD>
  63.  
  64. <!SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
  65.  
  66.    // Create and connect the database object
  67.    MSDBConnection1 = new MSDBConnection("test", "ODBC","MS Access", "Northwind","admin","",false);
  68.    MSDBConnection1.connect();
  69.  
  70.    // Create the query object
  71.    MSDBQuery1 = new MSDBQuery("MSDBQuery1", "MSDBConnection1", false, "*", "Customers", "customerID > 7", "lastname");
  72.  
  73.    // Create the dynafield object
  74.    MSDBDynaField1 = new MSDBDynaField( "MSDBDynaField1",
  75.                             "true",   
  76.                             "MSDBQuery1",
  77.                             "",
  78.                             "ShipCity",
  79.                             "string",
  80.                             "false",
  81.                             10,
  82.                             10,
  83.                             1,
  84.                             "Arial",
  85.                             "+0",
  86.                             "black",
  87.                             "false",
  88.                             "false",
  89.                             "false");
  90. <!/SCRIPT>
  91.  
  92. <META NAME="Generator" CONTENT="NetObjects Fusion 2.0 for Windows">
  93.  
  94. </HEAD>
  95. <body>
  96.    
  97.    write("<FORM METHOD=POST>");   
  98. <%
  99.    MSDBConnection1.render()
  100.    MSDBDynaField1.render()
  101. %>
  102.    write("</FORM>");
  103.    
  104. </BODY>
  105. </HTML>
  106.  
  107. =====================================================================*/
  108.  
  109. //
  110. // MSDBDynaField object constructor
  111. //
  112. function MSDBDynaField(
  113.                   name,
  114.                   useQuery,
  115.                   queryComponentName,
  116.                   defaultValue,
  117.                   dataField,
  118.                   dataType,
  119.                   isEditable,
  120.                   visibleLength,
  121.                   maxLength,
  122.                   visibleHeight,
  123.                   font,
  124.                   fontSize,
  125.                   fontColor,
  126.                   bold,
  127.                   italic,
  128.                   underline)
  129. {
  130.    // Assign property values
  131.    
  132.    this.name = name;
  133.    this.useQuery = useQuery;
  134.    this.queryComponentName = queryComponentName;
  135.    this.defaultValue = defaultValue;
  136.    this.dataField   = dataField;
  137.    this.dataType = dataType;
  138.    this.isEditable = isEditable;
  139.    this.visibleLength = visibleLength;
  140.    this.visibleHeight = visibleHeight
  141.    this.maxLength = maxLength;
  142.    this.font = font;
  143.    this.fontSize = fontSize + "";
  144.    this.fontColor = fontColor;
  145.    this.bold = bold;
  146.    this.italic = italic;
  147.    this.underline = underline;
  148.    
  149.    // Define Methods
  150.    this.getColumnValue = dfGetColumnValue;
  151.    this.render = dfRender;
  152.    this.emitProperties = dfEmitProperties;
  153.  
  154.    if (this.useQuery == "true") {
  155.       // Increment global cursor usage counter since this component will try to use the cursor
  156.       incCursorCallCount();
  157.    }
  158.    
  159. }    //END MSDBDynaField Constructor.
  160.  
  161. //
  162. // Method - dbEmitProperties()
  163. // emits all the object's properties.  Used as a debuging tool to verify correct
  164. // manipulation of the object.
  165. //
  166. function dfEmitProperties ()
  167. {
  168.       debug("Writing MSDBDynaField properties...");
  169.       write("\n<BR><B>MSDBDynaField Properties:</B>");
  170.       write("\n<BR>name = " + this.name);
  171.       write("\n<BR>useQuery = " + this.useQuery);
  172.       write("\n<BR>defaultValue = " + this.defaultValue);
  173.       write("\n<BR>dataField = " + this.dataField);
  174.       write("\n<BR>dataType = " + this.dataType);
  175.       write("\n<BR>isEditable = " + this.isEditable);
  176.       write("\n<BR>visibleLength = " + this.visibleLength);
  177.       write("\n<BR>visibleHeight = " + this.visibleHeight);
  178.       write("\n<BR>font = " + this.font);
  179.       write("\n<BR>fontSize = " + this.fontSize);
  180.       write("\n<BR>fontColor = " + this.fontColor);
  181.       write("\n<BR>bold = " + this.bold);
  182.       write("\n<BR>italic = " + this.italic);
  183.       write("\n<BR>underline = " + this.underline);
  184.       write("<BR>");
  185. }    // END dfEmitProperties;
  186.  
  187.  
  188. /* Method of MSDBDynaField - GetColumnValue
  189.    Check if the dataField property is not null or blank, 
  190.    same for the queryComponentName property.
  191.    If one of the checks fail then return a blank string. Otherwise the
  192.     method uses the eval argument to parse together a value
  193.     for the Query that the MSDBDynaField refers to.
  194. */
  195. function dfGetColumnValue() {
  196.    var retStr = '';
  197.    var dynaCursor = new Object();
  198.  
  199.    if (  (this.dataField == null) || 
  200.          (this.dataField == "") || 
  201.          (this.queryComponentName == null) || 
  202.          (this.queryComponentName == "")   ) {   
  203.       return "";
  204.    }
  205.    else {
  206.       // Get the current cursor for the Query. If none exists getCurrentCursor
  207.       // will create it.                              
  208.       //debug("Getting cursor from query '"+ this.queryComponentName + "'");
  209.       dynaCursor = eval(this.queryComponentName + ".getCurrentCursor()");
  210.       //dynaCursor = Session("MSDBQuery1");
  211.               //debug("val is '" + dynaCursor.Fields(this.dataField) + "'")
  212.  
  213.       if (dynaCursor != null) {
  214.           //debug("Cursor not null");
  215.          // Check to see if cursor is initialized. If it is not then initialize it
  216.          if (eval(this.queryComponentName + ".initializeCursor()")) {
  217.              //debug("Cursor initialized, attempting to get field '" + this.dataField + "'");
  218.              //debug("val is '" + dynaCursor.Fields(this.dataField) + "'")
  219.              // Retrieve the value for the MSDBDynaField                             
  220.              
  221.              if (dynaCursor.fields(this.dataField) != null) {
  222.                 // If Date value, format before checking for null because
  223.                 // JScript cannot detect this datatype untill it is formated.
  224.                 // This is a bug specific to JScript.
  225.                 if (!(this.dataType == "date" && formatDataValue (dynaCursor.fields(this.dataField), this.dataType) == "")) 
  226.                     retStr = dynaCursor.fields(this.dataField); 
  227.                 
  228.                 // If boolean return to numeric representation
  229.                 // This fixes a JScript nuisance that is automaticly
  230.                 // converting boolean values to non numbers.
  231.                 if (this.dataType == "boolean")  
  232.                     retStr = (retStr+"" == "false") ? "0":"-1"
  233.  
  234.                 //debug("Getting field");
  235.             }
  236.          }
  237.       }
  238.       else {
  239.          write("\n<BR>Unable to obtain a valid cursor.");            
  240.       }  
  241.  
  242.    } // end "if (   (this.dataField == null) || ..."
  243.   
  244.    return retStr;
  245. }    // END method GetColumnValue
  246.  
  247.  
  248. /*   Method of MSDBDynaField - dfRender
  249.     This method first examines the this.isEditable variable of the MSDBDynaField object 
  250.     if isEditable is true, then the method writes out the HTML statement to generate
  251.     an edit box. If it is false, then it examines the font and other cosmetic properties
  252.     of the MSDBDynaField, and generates the appropriate HTML.
  253.     NOTE! The MSDBDynaField.render() method depends of an existing FORM tag
  254.     allready existing in the HTML. It will not appear if it is set to isEditable = true
  255.     and no FORM tag exisits.
  256. */
  257. function dfRender() {
  258.  
  259.    var columnValue;
  260.    
  261.    // if useQuery is true, then get the column value from the cursor.
  262.    // otherwise use the defaultValue,
  263.    if (this.useQuery == "true") {
  264.       if (this.dataType.toUpperCase() == "DATE") {
  265.          columnValue = new Object();
  266.       }
  267.       columnValue = this.getColumnValue();
  268.   }
  269.    else
  270.       columnValue = this.defaultValue;
  271.  
  272.    // output the hidden field for the dataType
  273.    var pre = "amaspHidden_";
  274.    var fieldPre = "amaspField_";  // Used to designate field values passed over in URL that will
  275.                                        // generally be used in the "where" clause of an SQL query
  276.    
  277.    write("\r\n<INPUT NAME=\"" + pre + this.dataField + "_dataType\" VALUE=\"" + this.dataType + "\" TYPE=\"HIDDEN\">");
  278.  
  279.    if (this.isEditable == "true") {
  280.         // If visibleHeight does not equal one then output a textarea, otherwise output a text input element
  281.         if (this.visibleHeight > 1)
  282.             write("<TEXTAREA NAME=\"" + fieldPre + this.dataField + "\" COLS=\"" + this.visibleLength + "\" ROWS=\"" + this.visibleHeight + "\">" + formatDataValue(columnValue, this.dataType) + "</TEXTAREA>")
  283.         else
  284.            // Format the data value based on its datatype before rendering               
  285.           write("<Input TYPE=text NAME=\"" + fieldPre + this.dataField + "\" VALUE=\"" + formatDataValue(columnValue, this.dataType) + "\" SIZE=" + this.visibleLength + " MAXLENGTH=" + this.maxLength + ">")
  286.           //write("<Input TYPE=text NAME=\"" + fieldPre + this.dataField + "\" VALUE=\"" + columnValue + "\" SIZE=" + this.visibleLength + " MAXLENGTH=" + this.maxLength + ">")
  287.    }
  288.    else {
  289.       write("<FONT COLOR="+this.fontColor+" SIZE= \"" + this.fontSize + "\" " +((this.font != null) ?  "FACE=\""+ this.font+"\"":"") +">");
  290.       if (this.bold == "true")
  291.          write("<B>");
  292.       if (this.italic == "true")
  293.          write("<I>");
  294.       if (this.underline == "true")
  295.          write("<U>");      
  296.  
  297.       // Format the data value based on its datatype before rendering               
  298.       //write(formatDataValue(columnValue, this.dataType));   
  299.       write(columnValue);
  300.       
  301.       if (this.bold == "true")
  302.          write("</B>");
  303.       if (this.italic == "true")
  304.          write("</I>");
  305.       if (this.underline == "true")
  306.          write("</U>");               
  307.       write("</FONT>")         
  308.    }   
  309.    
  310.    // Decrement global cursor usage counter since this component has tried to use the cursor
  311.    // If the counter has reached zero after doing so, then this is the last cursor using
  312.    // component on the page, so call the DBQuery object's "cursorClose()" method to close
  313.    // the cursor if it's still open.
  314.    if (this.useQuery == "true") {
  315.        decCursorCallCount(this.queryComponentName);
  316.    } // end if
  317.  
  318. }    // END method dfRender
  319. </SCRIPT>
  320.